// pages/applyRefund/applyrRefund.js
//获取应用实例
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    reasonArray:['预约不上','商家营业但不接待','商家停业/装修/转让','去过了，不太满意','朋友/网上评价不好','买多了/买错了','计划有变，没时间消费','后悔了，不想要了','联系不上商家'],
    showall:false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.setData({
      options:options
    })
    that.getData();
  },
  getData:function(){
    var that = this;
    app.getLoginSession(function (session) {
      wx.request({
        url: app.api,
        data: {
          app: 'refund',
          act: 'index',
          order_id: that.data.options.order_id,
          order_sn: that.data.options.order_sn,
          t_session:session
      },
        success: function (res) {
          var data = res.data;
          if (data.done && data.retval) {
            that.setData({
              data: data.retval
            })
            console.log(that.data.data)
          }
        }
      })
    })
    
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },
  bindPickerChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index: e.detail.value
    })
  },
  // 显示所有菜单
  show_all: function () {
    var that = this;
    that.setData({
      showall: that.data.showall == true ? false : true
    })
  },
  //描述
  description:function(res){
    console.log(res);
    var that = this;
    that.setData({
      content:res.detail.value
    })
  },
  submit:function(){
    var that = this;
    if (that.data.index==undefined){
      wx.showModal({
        title: '提示',
        content: '请选择退款原因'
      })
    }else{
      app.getLoginSession(function (session) {
        wx.request({
          url: app.api,
          data: {
            app: 'refund',
            act: 'refund_order',
            order_id: that.data.options.order_id,
            reason: that.data.reasonArray[that.data.index],
            content: that.data.content!=undefined?that.data.content:'',
            t_session:session
          },
          success: function (res) {
            var data = res.data;
            if(data.done&&data.retval){
              wx.redirectTo({
                url: '/pages/logistics/logistics?order_id='+that.data.options.order_id
              })
            }else{
              wx.showToast({
                title: '请重试！',
              })
            }
          },
          fail:function(res){
            wx.showToast({
              title: '接口请求错误',
            })
          }
        })
      })
    }
  }
})